import { Route, Redirect } from 'react-router-dom'
const AuthRoute = ({ children, component: Component, ...rest }) => {
  return (
    <Route
      {...rest}
      render={props => {
        const token = localStorage.getItem('token')
        if (token) {
          // if (children) {
          //   return children
          // } else {
          //   return <Component></Component>
          // }
          return children ? children : <Component />
        } else {
          return <Redirect to={`/login?redirect=${props.location.pathname}`} />
        }
      }}
    />
  )
}

export default AuthRoute
